package org.tcs.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MailTesterController {

	@Autowired
	private JavaMailSenderImpl mailSender;
	@Autowired
	SimpleMailMessage mailMessage;

	@RequestMapping("/mail")
	public @ResponseBody String handleTestRequest() {
		SimpleMailMessage msg = new SimpleMailMessage(mailMessage);
		msg.setTo("example@mail.com"); 
		msg.setText("Test mail from spring mail");
		msg.setSubject("Test mail");
		try {
			mailSender.send(msg);			
		} catch (Exception e) {
			
			return "Problem in sending mail check the logs";
		}
		return "Mail sent sucessfully";
	}
}
